import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import "../component" as C
import "qrc:/component/ZGlobal.js" as Global

C.ZModelRect {
    id: machineRect
    x:0
    y:0
    width: 800
    height: 530
    color: "#F3F7FB"
    radius: 10
    visible: false

    Image {
        x: 40
        y: 40
        source: "qrc:/assets/greenrect.png"
        width: 16
        height: 28
        fillMode: Image.PreserveAspectFit
    }

    Label{
        x:68
        y:36
        Text{
            text: "注册"
            font.pixelSize: 28
            color: "#333333"
            font.bold: true
        }
    }

    Label{
        x:40
        y:108
        Text{
            text: "本机识别码： " + systemInfo.machineId
            font.pixelSize: 24
            color: "#333333"
        }
    }


    Label{
        x:40
        y:168
        Text{
            text: "剩余次数： 100"
            font.pixelSize: 24
            color: "#333333"
        }
    }

    Label{
        x:40
        y:228
        Text{
            id: deadLine
            text: "证书到期："
            font.pixelSize: 24
            color: "#333333"
        }
    }

    Label{
        x:40
        y:288
        Text{
            text: "注册码"
            font.pixelSize: 24
            color: "#333333"
        }
    }

    C.ZInputImage {
        id: serialNumber
        text: systemInfo.getSerialNumber()
        x: 40
        y: 335
        placeholderText: "请输入正确的注册码"
        onTextChanged: {
            // 1. 获取最新输入的文本
            console.log("当前输入：", text);
            if(systemInfo.checkSerialNumber(text)){
                deadLine.text = "证书到期： " + systemInfo.getDeadLine(text);
                errInfo.text="注册码正确，点击确定后保存"
                errInfo.color= "green"
            }else{
                deadLine.text = "证书到期： 未知";
                errInfo.text="请输入正确的注册码"
                errInfo.color= "red"
            }
        }
    }

    Label{
        x:40
        y:402
        Text{
            id: errInfo
            text: "请输入正确的注册码"
            font.pixelSize: 20
            color: "red"
        }
    }

    C.ZButton{
        x: 329
        y: 430
        text: "取消"
        onClicked: {
            // console.log(">>>>>>>>>>>>")
            machineRect.visible=false;
        }
    }


    C.ZButton{
        x: 561
        y: 430
        text: "确定"
        color: "#178FCD"
        fontColor: "white"
        onClicked: {
            console.log("save:", serialNumber.text);
            if (serialNumber.text.length === 0) return;
            systemInfo.saveSerialNumber(serialNumber.text,userInfo.currentLogin.name);
            serialNumberText.text = serialNumber.text
            machineRect.visible=false
            console.log("save over");
        }
    }
}

